package com.sqly.doc.menu.grjbxx;



import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.TextView;

import com.sqly.doc.R;
import com.sqly.doc.view.TabFragment;

/**
 * 个人基本信息
 * Created by Administrator on 2017-11-14.
 */
public class user_info extends AppCompatActivity {

    private TabLayout tabLayout = null;

    private ViewPager viewPager;

    private Fragment[] mFragmentArrays = new Fragment[6];

    private String[] mTabTitles = new String[6];
    Context con=user_info.this;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        supportRequestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.tab_layout);
        tabLayout = (TabLayout) findViewById(R.id.tablayout);
        viewPager = (ViewPager) findViewById(R.id.tab_viewpager);
        initView();
    }

    private void initView() {
        mTabTitles[0] = "基础信息";
        mTabTitles[1] = "文化、职业、婚姻信息";
        mTabTitles[2] = "医疗支付方式";
        mTabTitles[3] = "药物过敏史、既往史、手术信息";
        mTabTitles[4] = "家族史、遗传病史、残疾情况";
        mTabTitles[5] = "家族情况生活环境";
        tabLayout.setTabMode(TabLayout.MODE_SCROLLABLE);
        //设置tablayout距离上下左右的距离
        //tab_title.setPadding(20,20,20,20);
        mFragmentArrays[0] = TabFragment.newInstance();
        mFragmentArrays[1] = TabFragment.newInstance();
        mFragmentArrays[2] = TabFragment.newInstance();
        mFragmentArrays[3] = TabFragment.newInstance();
        mFragmentArrays[4] = TabFragment.newInstance();
        mFragmentArrays[5] = TabFragment.newInstance();

        viewPager.setAdapter(new MorePagerAdapter());
        //将ViewPager和TabLayout绑定
        tabLayout.setupWithViewPager(viewPager);
    }

    final class MorePagerAdapter extends PagerAdapter {

        @Override
        public int getCount() {
            return 6;
        }

        @Override
        public Object instantiateItem(ViewGroup container, int position) {
            View v = null;
            switch (position) {
                case 0:
                    v = LayoutInflater.from(user_info.this).inflate(R.layout.grjbxx_jcxx, null);
                    break;
                case 1:
                    v = LayoutInflater.from(user_info.this).inflate(R.layout.grjbxx_whzy, null);
                    break;
                case 2:
                    v = LayoutInflater.from(user_info.this).inflate(R.layout.grjbxx_zffs, null);
                    break;
                case 3:
                    v = LayoutInflater.from(user_info.this).inflate(R.layout.grjbxx_ywgm, null);
                    break;
                case 4:
                    v = LayoutInflater.from(user_info.this).inflate(R.layout.grjbxx_jzs, null);
                    break;
                case 5:
                    v = LayoutInflater.from(user_info.this).inflate(R.layout.grjbxx_jzshhj, null);
                    break;
                default:
                    break;
            }
            container.addView(v);
            return v;
        }

        @Override
        public void destroyItem(ViewGroup container, int position, Object object) {
            Log.i("状态","摧毁");
            (container).removeView((View) object);
        }

        @Override
        public boolean isViewFromObject(View view, Object object) {
            return view == object;
        }

        @Override
        public CharSequence getPageTitle(int position) {
            return mTabTitles[position];
        }
    }
}
